package com.lry.web.fiction.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lry.web.fiction.entity.FictionChapter;
import com.lry.web.fiction.mapper.FictionChapterMapper;
import com.lry.web.fiction.service.FictionChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@Service
public class FictionChapterServiceImpl implements FictionChapterService {
    @Autowired
    FictionChapterMapper fictionChapterMapper;




    public int setFictionChapter(FictionChapter fictionChapter) {
        int insert = fictionChapterMapper.insert(fictionChapter);
        return insert;
    }


    public List<FictionChapter> getFictionChapters(String fictionId) throws IOException {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("fiction_id",fictionId);
        List<FictionChapter> fictionChapters = fictionChapterMapper.selectList(wrapper);

        return fictionChapters;

    }


    public int deleteByFVId(String fVId) throws Exception {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("fiction_variable_id",fVId);

        return fictionChapterMapper.delete(wrapper);
    }

    public int deleteByFictionId(String fictionId) throws Exception {
        List<String> list=  Arrays.asList(fictionId.split(","));
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("fiction_id",list);

        return fictionChapterMapper.delete(wrapper);
    }




}

